from django.db import models
from django.contrib.auth.models import AbstractUser, AbstractBaseUser


# Create your models here.
# 职员表
class EmployeeUser(AbstractUser):
    """
    职位有后厨、前台、服务生、老板四种，四选一作为字符串存入
    """
    job = models.CharField(max_length=20, verbose_name='职位')
    name = models.CharField(max_length=20, verbose_name='姓名')
    phone = models.CharField(max_length=20, verbose_name='电话')

    class Meta:
        db_table = 'rest_user'
        verbose_name_plural = verbose_name = '职员表'
        pass

    pass


# 用户表
class client(models.Model):
    """
    level字段为用户、会员二选一
    其余字段均有默认值，创建时无需设值
    """
    id = models.AutoField(primary_key=True, verbose_name='编号')
    level = models.CharField(max_length=20, verbose_name='等级', default='用户')
    createTime = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    allCost = models.IntegerField(verbose_name='消费总额', default=0)
    name = models.CharField(max_length=20, verbose_name='姓名', default='临时用户')
    sex = models.CharField(max_length=20, verbose_name='性别', default='临时用户')
    age = models.CharField(max_length=20, verbose_name='年龄', default='临时用户')
    phone = models.CharField(max_length=20, verbose_name='电话', default='临时用户')
    idCard = models.CharField(max_length=18, verbose_name='身份证号', default='临时用户')

    class Meta:
        db_table = 'rest_client'
        verbose_name_plural = verbose_name = '顾客表'
        pass

    pass


# 餐桌表
class table(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='编号')
    state = models.BooleanField(default=True, verbose_name='状态')
    number = models.IntegerField(verbose_name='可容纳人数')
    cost = models.IntegerField(verbose_name='基础费用', default=0)

    class Meta:
        db_table = 'rest_table'
        verbose_name_plural = verbose_name = '餐桌表'
        pass

    pass


# 订桌表
class preTable(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='编号')
    vipid = models.ForeignKey('client', on_delete=models.CASCADE, verbose_name='会员号')
    tableid = models.ForeignKey('table', on_delete=models.CASCADE, verbose_name='餐桌号')

    class Meta:
        db_table = 'rest_preTable'
        verbose_name_plural = verbose_name = '订桌表'
        pass

    pass


# 点餐表
class order(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='编号')
    order_time = models.DateTimeField(auto_now_add=True, verbose_name='点餐时间')
    clientid = models.ForeignKey('client', on_delete=models.CASCADE, verbose_name='会员号')
    dishesid = models.ForeignKey('dishes', on_delete=models.CASCADE, verbose_name='菜品号')
    operatorid = models.ForeignKey('EmployeeUser', on_delete=models.CASCADE, verbose_name='操作员')
    tableid = models.ForeignKey('table', on_delete=models.CASCADE, verbose_name='餐桌号')
    done = models.BooleanField(default=False, verbose_name='菜品是否已做出')

    class Meta:
        db_table = 'rest_order'
        verbose_name_plural = verbose_name = '点餐表'
        pass

    pass


# 菜品表
class dishes(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='编号')
    name = models.CharField(max_length=50, verbose_name='菜品名称')
    price = models.IntegerField(verbose_name='菜品价格')

    class Meta:
        db_table = 'rest_dishes'
        verbose_name_plural = verbose_name = '菜品表'
        pass

    pass


# 食材表
class ingredients(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='编号')
    name = models.CharField(max_length=20, verbose_name='食材名称')
    num = models.IntegerField(verbose_name='剩余数量', default=0)

    class Meta:
        db_table = 'rest_ingredients'
        verbose_name_plural = verbose_name = '食材表'
        pass

    pass


# 菜单-食材表
class dish_ingre(models.Model):
    DI_Id = models.AutoField(primary_key=True, verbose_name='记录编号')
    DI_ingr = models.ForeignKey('ingredients', on_delete=models.CASCADE, verbose_name='食材名称')
    DI_dish = models.ForeignKey('dishes', on_delete=models.CASCADE, verbose_name='菜品名称')
    DI_Num = models.IntegerField(verbose_name='需要食材的数量')

    class Meta:
        db_table = 'rest_dish_ingre'
        verbose_name_plural = verbose_name = '菜品-食材表'
        pass

    pass


# 消费单据表
class bill(models.Model):
    id = models.AutoField(primary_key=True)
    clientId = models.ForeignKey('client', on_delete=models.CASCADE, verbose_name='用户号')
    operatorId = models.ForeignKey('EmployeeUser', on_delete=models.CASCADE, verbose_name='操作员')
    dishId = models.ForeignKey('dishes', on_delete=models.CASCADE, verbose_name='菜品名称')
    billTime = models.DateTimeField(auto_now_add=True, verbose_name='结账时间')
    tableId = models.ForeignKey('table', on_delete=models.CASCADE, verbose_name='餐桌号')
    billId = models.CharField(max_length=50, verbose_name='多条记录所属的账单id')

    class Meta:
        db_table = 'rest_bill'
        verbose_name_plural = verbose_name = '账单表'
        pass

    pass


# 信息表
class message(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='信息序列号')
    txt = models.CharField(max_length=50, verbose_name='信息内容')
    time = models.DateTimeField(auto_now_add=True, verbose_name='信息发送时间')
    sourceId = models.ForeignKey('EmployeeUser', on_delete=models.CASCADE, verbose_name='源雇员', related_name='sourceId')
    targetId = models.ForeignKey('EmployeeUser', on_delete=models.CASCADE, verbose_name='目标雇员', related_name='targetId')

    class Meta:
        db_table = 'rest_message'
        verbose_name_plural = verbose_name = '通知表'
        pass

    pass


class dayaccount(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='序列号')
    time = models.DateTimeField(auto_now_add=True, verbose_name='清账时间')
    pass


# 操作日志表
class myLog(models.Model):
    """
    总结操作种类
    职员登录
    职员表：增加（忽略）
    餐桌表：增、删、改
    订卓表：增、删
    点餐表：增、删、改
    菜品表：增、删
    食材表：增、改
    食材-菜单表：增
    消费单据表：增
    信息表：增

    """
    id = models.AutoField(primary_key=True)
    time = models.DateTimeField(auto_now_add=True, verbose_name='操作完成时间')
    operatorId = models.ForeignKey('EmployeeUser', on_delete=models.CASCADE, verbose_name='操作员')
    text = models.CharField(max_length=50, verbose_name='操作类型')

    class Meta:
        db_table = 'rest_log'
        verbose_name_plural = verbose_name = '日志'
        pass

    pass